home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / bfloat.com / BFLOAT.DOC < prev    next >
Encoding:
Text File  |  1989-05-14  |  4.8 KB  |  122 lines

  1. {$A-,B-,D-,E+,F-,I-,L-,N+,O-,R-,S-,V-}
  2. unit BFLOAT;
  3. (*
  4.             MicroSoft Binary Float to IEEE format Conversion
  5.                     Copyright (c) 1989 J.P. Ritchey
  6.                             Version 1.0
  7.  
  8.          This software is released to the public domain.  Though
  9.          tested, there could be some errors.  Any reports of bugs
  10.          discovered would be appreciated. Send reports to
  11.                  Pat Ritchey     Compuserve ID 72537,2420
  12. *)
  13. interface
  14.  
  15. type
  16.   bfloat4 = record
  17.     { M'Soft single precision }
  18.     mantissa : array[5..7] of byte;
  19.     exponent : byte;
  20.     end;
  21.  
  22.   Bfloat8 = record
  23.     { M'Soft double precision }
  24.     mantissa : array[1..7] of byte;
  25.     exponent : byte;
  26.     end;
  27.  
  28.  
  29. Function Bfloat4toExtended(d : bfloat4) : extended;
  30. Function Bfloat8toExtended(d : Bfloat8): extended;
  31.  
  32. { These routines will convert a MicroSoft Binary Floating point
  33.   number to IEEE extended format.  The extended is large enough
  34.   to store any M'Soft single or double number, so no over/underflow
  35.   problems are encountered.  The Mantissa of an extended is large enough
  36.   to hold a BFloatx mantissa, so no truncation is required.
  37.  
  38.   The result can be returned to TP single and double variables and
  39.   TP will handle the conversion.  Note that Over/Underflow can occur
  40.   with these types. }
  41.  
  42. Function HexExt(ep:extended) : string;
  43.  
  44. { A routine to return the hex representation of an IEEE extended variable
  45.   Left in from debugging, you may find it useful }
  46.  
  47. Function ExtendedtoBfloat4(ep : extended; var b : bfloat4) : boolean;
  48. Function ExtendedtoBfloat8(ep : extended; var b : Bfloat8) : boolean;
  49.  
  50. { These routines are the reverse of the above, that is they convert
  51.   TP extended => M'Soft format.  You can use TP singles and doubles
  52.   as the first parameter and TP will do the conversion to extended
  53.   for you.
  54.  
  55.   The Function result returns True if the conversion was succesful,
  56.   and False if not (because of overflow).
  57.  
  58.   Since an extended can have an exponent that will not fit
  59.   in the M'Soft format Over/Underflow is handled in the following
  60.   manner:
  61.     Overflow:  Set the Bfloatx to 0 and return a False result.
  62.     Underflow: Set the BFloatx to 0 and return a True Result.
  63.  
  64.   No rounding is done on the mantissa.  It is simply truncated to
  65.   fit. }
  66.  
  67.  
  68. Function BFloat4toReal(b:bfloat4) : Real;
  69. Function BFloat8toReal(b:bfloat8) : Real;
  70.  
  71. { These routines will convert a MicroSoft Binary Floating point
  72.   number to Turbo real format.  The real is large enough
  73.   to store any M'Soft single or double Exponent, so no over/underflow
  74.   problems are encountered.  The Mantissa of an real is large enough
  75.   to hold a BFloat4 mantissa, so no truncation is required.  The
  76.   BFloat8 mantissa is truncated (from 7 bytes to 5 bytes) }
  77.  
  78. Function RealtoBFloat4(rp: real; var b:bfloat4) : Boolean;
  79. Function RealtoBFloat8(rp : real; var b:bfloat8) : Boolean;
  80.  
  81. { These routines do the reverse of the above.  No Over/Underflow can
  82.   occur, but truncation of the mantissa can occur
  83.   when converting Real to Bfloat4 (5 bytes to 3 bytes).
  84.  
  85.   The function always returns True, and is structured this way to
  86.   function similar to the IEEE formats }
  87.  
  88.          ----------------end-of-author's-documentation---------------
  89.  
  90.                         Software Library Information:
  91.  
  92.                    This disk copy provided as a service of
  93.  
  94.                         The Public (Software) Library
  95.  
  96.          We are not the authors of this program, nor are we associated
  97.          with the author in any way other than as a distributor of the
  98.          program in accordance with the author's terms of distribution.
  99.  
  100.          Please direct shareware payments and specific questions about
  101.          this program to the author of the program, whose name appears
  102.          elsewhere in  this documentation. If you have trouble getting
  103.          in touch with the author,  we will do whatever we can to help
  104.          you with your questions. All programs have been tested and do
  105.          run.  To report problems,  please use the form that is in the
  106.          file PROBLEM.DOC on many of our disks or in other written for-
  107.          mat with screen printouts, if possible.  The P(s)L cannot de-
  108.          bug programs over the telephone.
  109.  
  110.          Disks in the P(s)L are updated monthly, so if you did not get
  111.          this disk  directly from the P(s)L,  you should be aware that
  112.          the files in this set may no  longer be the current versions.
  113.  
  114.          For a copy of the latest monthly software library newsletter
  115.          and a list of the 1,800+ disks in the library, call or write
  116.  
  117.                         The Public (Software) Library
  118.                               P.O.Box 35705 - F
  119.                            Houston, TX 77235-5705
  120.                                (713) 665-7017
  121.  
  122.